﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using DotNet.Business;
using DotNet.Model;
using DotNet.Common;
public partial class Admin_adminHotQuestion : System.Web.UI.Page
{
    hotQuestionBll hqBll = new hotQuestionBll();
    int pagesize = 20;
    private static readonly object objSync = new object();
    public string input = "<input id=\"HiddenUrl\" type=\"text\" value=\"&CurrentIndex=1\" />";
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Request.QueryString["action"]!=null)
            {
                string action = Request.QueryString["action"];
                switch (action.Trim())
                {
                    case "delAll":
                        Delete();
                        break;                   
                    case "editAll":
                        editAll();
                        break; 
                    default:
                        break;
                }
            }
            bindHq();
        }
    }

    



    #region 修改
    public void editAll()
    {
        string id = Request.QueryString["id"];
        if (id.Contains(","))
        {
            lock (objSync)
            {
                string[] idParam = id.Split(',');
                for (int i = 0; i <= idParam.Length - 1; i++)
                {
                    hotQuestion hq = hqBll.GetModel(Convert.ToInt32(idParam[i]));
                    hq.hotQuestionID = Convert.ToInt32(idParam[i]);
                    if (Request.Form["hqTitle" + idParam[i] + ""].ToString().Trim() == "")
                    {
                        return;
                    }
                    hq.hotQuestionTitle = Request.Form["hqTitle" + idParam[i].ToString()].ToString();
                    if (hqBll.Update(hq))
                    {
                    }
                    else
                        return;
                }
            }
        }
        else 
        {
            hotQuestion hq = hqBll.GetModel(Convert.ToInt32(id));
            if (Request.Form["hqTitle" + id+ ""].ToString().Trim() == "")
            {
                return;
            }
            hq.hotQuestionTitle = Request.Form["hqTitle" +id].ToString();
            if (hqBll.Update(hq))
            {

            }
            else
                return;
        }
    }
    #endregion

    #region 删除问题
    public void Delete() 
    {
        int id = Convert.ToInt32(Request.QueryString["id"]);
        if (hqBll.Delete(id))
        {
            
        }
    }
    #endregion

    #region 绑定问题
    public void bindHq() 
    {
        if(Request.QueryString["CurrentIndex"]!=null)
        {
            _currentIndex = Convert.ToInt32(Request.QueryString["CurrentIndex"]);
        }
        DataTable dt = hqBll.pagingForHotQuestion(_currentIndex, pagesize);
        if (dt.Rows.Count==0&&_currentIndex>1)
        {
            --_currentIndex;
            dt = hqBll.pagingForHotQuestion(_currentIndex, pagesize);
        }
        input = "<input id='HiddenUrl' type='hidden' value='&CurrentIndex=" + _currentIndex +"'/>";
        this.Repeater1.DataSource = dt;
        this.Repeater1.DataBind();
    }
    #endregion

    #region 分页按钮
    public void htmlPaging()
    {
        string str = null;
        int count = 0;
        count = hqBll.getRecordCount();
        int pcount = count % pagesize == 0 ? count / pagesize : count / pagesize + 1;
        str = "页次：" + _currentIndex + "/" + pcount + "  每页" + pagesize + " 总收录数据" + count + "条";
        str += HtmlControls.pagIng(_currentIndex, pcount, "adminHotQuestion.aspx?&CurrentIndex", "pageaa", "pagecurrent");
        Response.Write(str);
    }
    #endregion

    #region 状态维护
    private int _currentIndex = 1;
    #endregion
}
